package xyz.lwm.lazycat.aop.matcher;

import xyz.lwm.lazycat.aop.info.MethodInfo;
import xyz.lwm.lazycat.utility.matcher.Matcher;

import java.lang.annotation.Annotation;

/**
 * aop matcher utils
 *
 * @author lwm
 */
public abstract class Matchers {

    /**
     * 类名匹配 <br>
     * 如: com.example.*.Hello    com.**.World
     *
     * @param pattern 类名通配符表达式
     * @return matcher for class name
     */
    public static Matcher<MethodInfo> classed(String pattern) {
        return new ClassNameMatcher(new ArrayMatcher<>(new StringPatternMatcher(pattern)));
    }

    /**
     * 类名匹配 <br>
     * 如: com.example.*.Pageable
     *
     * @param pattern 类上的注解类名通配符表达式
     * @return matcher for class annotation
     */
    public static Matcher<MethodInfo> classAnnotated(String pattern) {
        return new ClassAnnotationMatcher(new ArrayMatcher<>(new StringPatternMatcher(pattern)));
    }

    /**
     * 类名匹配 <br>
     *
     * @param annotationType 注解类
     * @return matcher for class annotation
     */
    public static Matcher<MethodInfo> classAnnotated(Class<? extends Annotation> annotationType) {
        return new ClassAnnotationMatcher(new ArrayMatcher<>(new StringEqualsMatcher(annotationType.getName())));
    }

    /**
     * 方法名匹配 <br>
     * 如: get*Info
     *
     * @param pattern 方法名通配符表达式
     * @return matcher for method name
     */
    public static Matcher<MethodInfo> method(String pattern) {
        return new MethodNameMatcher(new StringPatternMatcher(pattern));
    }

    /**
     * 方法名匹配 <br>
     * 如: com.example.*.Pageable
     *
     * @param pattern 方法上的注解类名通配符表达式
     * @return matcher for method annotation
     */
    public static Matcher<MethodInfo> methodAnnotated(String pattern) {
        return new MethodAnnotationMatcher(new ArrayMatcher<>(new StringPatternMatcher(pattern)));
    }

    /**
     * 方法名匹配 <br>
     *
     * @param annotationType 注解类
     * @return matcher for method annotation
     */
    public static Matcher<MethodInfo> methodAnnotated(Class<? extends Annotation> annotationType) {
        return new MethodAnnotationMatcher(new ArrayMatcher<>(new StringEqualsMatcher(annotationType.getName())));
    }

    /**
     * around切面匹配
     *
     * @param around around注解
     * @return around matcher
     */
//    public static Matcher<MethodInfo> around(Around around) {
//        return new AroundMatcher(around);
//    }

}
